#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

const int N = 60;
char gra[N][N];
int n, m;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> gra[i][j];

    int res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            if (gra[i][j] == 'Y')
            {
                res++;
                for (int k = 0; i + k < n && j + k < m && (gra[i + k][j + k] == 'G' || gra[i + k][j + k] == 'Y'); k++)
                    if (gra[i + k][j + k] == 'G')    gra[i + k][j + k] = 'B';
                    else gra[i + k][j + k] = 'X';
            }
            else if (gra[i][j] == 'B')
            {
                res++;
                for (int k = 0; i + k < n && j - k >= 0 && (gra[i + k][j - k] == 'G' || gra[i + k][j - k] == 'B'); k++)
                    if (gra[i + k][j - k] == 'G')    gra[i + k][j - k] = 'Y';
                    else gra[i + k][j - k] = 'X';
            }
            else if (gra[i][j] == 'G')
            {
                res += 2;
                for (int k = 0; i + k < n && j + k < m && (gra[i + k][j + k] == 'G' || gra[i + k][j + k] == 'Y'); k++)
                    if (gra[i + k][j + k] == 'G')    gra[i + k][j + k] = 'B';
                    else gra[i + k][j + k] = 'X';
                for (int k = 0; i + k < n && j - k >= 0 && (gra[i + k][j - k] == 'G' || gra[i + k][j - k] == 'B'); k++)
                    if (gra[i + k][j - k] == 'G')    gra[i + k][j - k] = 'Y';
                    else gra[i + k][j - k] = 'X';
            }

        }

    cout << res << endl;
    return 0;
}